import re, time
from datetime import datetime, timedelta
from app.models.redis_model import redis_conn
from app.models.mongo_model import mongo_conn

mon = mongo_conn()
collection = mon['students']
# print(collection)
student = {
 'id': '20170101',
 'name': 'jordan',
 'age': 20,
 'gender': 'male'
}
result = collection.insert_one(student)
print(result)
# rc = redis_conn()
# rc.setex("118.116.107.72", 10, "windows")
# obj = re.compile(
#     r'(?P<ip>.*?)- - \[(?P<times>.*?)\] "(?P<request>.*?)" (?P<status>.*?) (?P<bytes>.*?) "(?P<referer>.*?)" "('
#     r'?P<ua>.*?)"')
# str = '118.116.107.72 - - [23/Jul/2022:12:34:40 +0000] "GET /index.php HTTP/1.1" 200 69003 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36 Edg/103.0.1264.62" "-"'
# s = str.strip()
# print(s)
# result = obj.match(s)
# ip = result.group("ip")
# print(ip)
# status = result.group("status")  # 状态码
# print(status)
# times = result.group("times").replace(" +0000", "")
# t = datetime.strptime(times, "%d/%b/%Y:%H:%M:%S")
# t = t + timedelta(hours=8)
# print(t)
# request = result.group("request").split()  # request处理
# print(request)
# ua = result.group("ua")
# print(ua)
# referer = result.group("referer")
# print(referer)